package ui.map 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author usual
	 */
	public class ZoomerMeasure extends MovieClip 
	{
		private var _zoomer:Zoomer;
		private var _currentZoomLevel:int = 0;
		public function ZoomerMeasure() 
		{
			addEventListener(Event.ADDED_TO_STAGE, _build);
		}
		
		private function _build(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, _build);
			addZoomer();
			addInteract();
		}
		
		private function addInteract():void 
		{
			_zoomer.thumb_mc.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			_zoomer.surface_mc.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			_zoomer.surface_mc.buttonMode = _zoomer.thumb_mc.buttonMode = true;
			
			
			
			_zoomer.plus_mc.buttonMode = _zoomer.minus_mc.buttonMode = true;
			
			_zoomer.plus_mc.addEventListener(MouseEvent.MOUSE_UP, _plusUp);
			_zoomer.minus_mc.addEventListener(MouseEvent.MOUSE_UP, _minusUp);
			
		}
		
		private function _minusUp(e:MouseEvent):void 
		{
			if (_currentZoomLevel > 0)
			{
				_currentZoomLevel -= 1;
				trace("[ZoomerMeasure._minusUp] ",_currentZoomLevel);
				if (_currentZoomLevel == 1)_onStageMouseUp(null, 65);
				if (_currentZoomLevel == 0)_onStageMouseUp(null, 99);
			}
		}
		
		private function _plusUp(e:MouseEvent):void 
		{
			if (_currentZoomLevel < 2)
			{
				_currentZoomLevel += 1;
				if (_currentZoomLevel == 1)_onStageMouseUp(null, 65);
				if (_currentZoomLevel == 2)_onStageMouseUp(null, 20);
			}
			
		}
		
		private function onMouseUp(e:MouseEvent):void 
		{
			var my:Number = this.mouseY;
			if (my > 77 && my < 270)_zoomer.thumb_mc.y = this.mouseY;
			_onStageMouseUp();
		}
		
		private function onMouseDown(e:MouseEvent):void 
		{
			trace("[ZoomerMeasure.onMouseDown] ");
			stage.addEventListener(MouseEvent.MOUSE_MOVE, _onMouseMove);
			stage.addEventListener(MouseEvent.MOUSE_UP, _onStageMouseUp);
		}
		
		private function _onStageMouseUp(e:MouseEvent=null,fakeMouseY:int=0):void 
		{
			stage.removeEventListener(MouseEvent.MOUSE_UP, _onStageMouseUp);
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, _onMouseMove);
			var wtr:int 	
			if (fakeMouseY == 0)
			{
				wtr = int((_zoomer.surface_mc.mouseY * 100 ) / _zoomer.surface_mc.height);
				//trace("[ZoomerMeasure._onStageMouseUp] ",wtr);
			}
			else
			{
				wtr = fakeMouseY;
				//trace("[ZoomerMeasure._onStageMouseUp] _currentZoomLevel",_currentZoomLevel);
				if (_currentZoomLevel == 0)_zoomer.thumb_mc.y = 270;
				if (_currentZoomLevel == 1)_zoomer.thumb_mc.y = 167;
				if (_currentZoomLevel == 2)_zoomer.thumb_mc.y = 77;
				
				//if (_currentZoomLevel == 3)_zoomer.thumb_mc.y = 167;
				//if (_currentZoomLevel == 0)_zoomer.thumb_mc.y = 270;
			}
			MovieClip(parent).zoomMap(wtr);
			
		}
		
		private function _onMouseMove(e:MouseEvent):void 
		{
			var my:Number = this.mouseY;
			if (my > 77 && my < 270)_zoomer.thumb_mc.y = this.mouseY;
			
		}
		
		private function addZoomer():void 
		{
			_zoomer = new Zoomer();
			addChild(_zoomer);
		}
	}

}